package com.microservices.cloud.controller;


import com.microservices.cloud.entities.CommonResult;
import com.microservices.cloud.entities.Payment;
import com.microservices.cloud.service.PaymentService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class OrderNacosController {

    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String serverURL;

    @GetMapping(value = "/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id") Long id)
    {
        return restTemplate.getForObject(serverURL+"/payment/nacos/"+id,String.class);
    }


    @GetMapping(value = "/consumer/configInfo")
    public String configInfo()
    {
        return restTemplate.getForObject(serverURL+"/configInfo",String.class);
    }



    @Autowired
    private PaymentService paymentService;


    @GetMapping(value = "/consumer/payment/feignFallBack/{id}")
    public CommonResult<Payment> feignFallBack(@PathVariable("id") Long id)
    {
        return paymentService.getPayment(id);
    }



}
